<script language="javascript">
    // apply filters
        var  applyFilter = jQuery(document).ready(function(){
        jQuery("#list_en").jqGrid({
            url: '<?php echo site_url() ?>/gestionentrega/getDataCompanias/',
            mtype: 'POST',
            datatype: 'json',
            colNames:['ID','Producto','C. Producto','Referencia','No. Dias','Contacto','Telefono1','Balance P.','Email','I-Gen','I-Contacto'],
         colModel :[
                {name:'IdReferencia', index:'Id_Referencia', width:2,hidden:true},
                {name:'Producto', index:'Id_Tipo_Producto', width:20},
                {name:'cProductos', index:'clasificacion_servicios', width:20},
                {name:'Referencia', index:'Referencia', width:30,search:true, stype:'text'},
                {name:'Dias', index:'Fecha_Inicio_Entrega', width:15},
                {name:'Contacto', index:'idTipoEntrada', width:20},
                {name:'Telefono1', index:'idTipoEntrada', width:18},
                {name:'Balance', index:'Balance_Pendiente', width:18},
                {name:'Email', index:'ProximoContacto', width:35},
                {name:'Gen', index:'Fecha_Inicio_Entrega', width:15},
                {name:'I-Contacto', index:'ProximoContacto', width:15}],
                                  
            pager: jQuery('#pager_en'),
            hiddengrid: false,
            sortname: 'Fecha_Inicio_Entrega',
            rowNum:5,
            rowList:[],                     
            sortorder: 'ASC',
            height: '100%',
            width: '630',
            imgpath: _base_url + 'public/css/jqgrid/flex/images',
            viewrecords: false,
            multiselect: false,
           onSelectRow: function(ids) 
            {
            	if(ids != null) 
            	{
            		var rec = jQuery("#list_en").getRowData(ids);
            		lol=ids;
           
            	       	
            	}
            },

            adjacents: 4,
            jsonReader: { repeatitems : false, IdReferencia: "0" }
        })
        
        
        .navGrid('#pager_en',{edit:false,add:false,del:false,search:false})
        
          
        .navButtonAdd('#pager_en',{caption:"", buttonimg: _base_url + "public/css/jqgrid/flex/images/text_columns.png", onClickButton:
        function()
        { 
         jQuery("#list_en").setColumns();
        } })
        
        .navButtonAdd('#pager_en',{caption:"Agregar", buttonimg: _base_url + "public/images/new.png", onClickButton:
        function(){ window.location = _site_url + "/CompanyEntrega/add"; } })
        
        .navButtonAdd('#pager_en',{caption:"Editar", buttonimg: _base_url + "public/images/edit.png", onClickButton:
        function(){ var id = jQuery('#list_en').getGridParam('selarrrow');
        var id = jQuery('#list_en').getGridParam('selarrrow');  
        var id=lol;   
        if (id.length > 0) 
        {
          
                var ret = jQuery("#list_en").getRowData(id);
                window.location = _site_url + '/CompanyEntrega/edit/' + ret.IdReferencia;
           
        } else { jAlert('Debe seleccionar al menos una Sociedad'); }
        return false; } })
        
      
        .navButtonAdd('#pager_en',{caption:"Entregar", buttonimg: _base_url + "public/images/edit.png", onClickButton:
        function(){ var id = jQuery('#list_en').getGridParam('selarrrow');
        var id = jQuery('#list_en').getGridParam('selarrrow');  
        var id=lol;   
        if (id.length > 0) 
        {
          
                var ret = jQuery("#list_en").getRowData(id);
                window.location = _site_url + '/CompanyEntrega/ent/' + ret.IdReferencia;
           
        } else { jAlert('Debe seleccionar al menos una Sociedad'); }
        return false; } })
        
       
        $('#apply_filter').bind('click', applyFilter);
        
        
    });

        var flAuto = true;
        var timeoutHnd; 

        function doSearch(ev)
        { 
              if(!flAuto) return; 
              // var elem = ev.target||ev.srcElement; 
              if(timeoutHnd) 
                  clearTimeout(timeoutHnd); 
                  timeoutHnd = setTimeout(gridReload,500); 
        } 
         
        function enableAutosubmit(state)
        { 
              flAuto = state; 
              jQuery("#submitButton").attr("disabled",state); 
        }
        
        function gridReload()
        { 
      	         var ba_mask = jQuery("#search_ba").val(); 
                 var ct_mask = jQuery("#search_ct").val();
                 var cd_mask = jQuery("#search_cd").val(); 

                  var array_search = cd_mask+'_'+ct_mask+'_'+ba_mask;
              
              jQuery("#list").setGridParam({url :'<?php echo site_url() ?>/CompanyEntrega/data/'+array_search, page : 1}).trigger('reloadGrid'); 
        }

        
    applyFilter.filterToolbar();

        function getCheckedValue(radioObj) 
         {
      	   if(!radioObj)
		       return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
     
</script>

<div class="table_container">


<table>

 <tr>
      <td style="padding: 5px;">
            <div id="titulo" style="padding: 4px;text-align: left;">
               
	  <a href="<?php echo site_url();?>/CompanyEntrega"><font style="font-size:15px;text-decoration: underline;">Pendiente Para Entrega <b><?php echo $numPediente;?></b></font></a> |
      <a href="<?php echo site_url();?>/indicadoresentrega"><font size = "3%" >Indicadores Entrega</font></a>
      
            </div>
       </td>
    </tr>

</tr>
<tr><td><div id="titulo">Las 5 Compa&ntilde;ias Mas Viejas dentro de los 45 Dias</div></td></tr>
<tr>
<tr>
<td>
    <table id="list_en" class="scroll"></table>
    <div id="pager_en" class="scroll" style="text-align:center;"></div>
</td>
 </tr>
   <?php $this->load->view('listgestionentrega');?>
</table>
</div>